<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>文档内容</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
</head>
<style>
    .icon {
       width: 2.5em; height: 2.5em;
       vertical-align: -0.15em;
       fill: currentColor;
       overflow: hidden;
    }

    .bottom{ margin-bottom: 10px; }
</style>
<body>
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-media-list" id="fileDetails">
            <!-- <li class="aui-list-item">
                <div class="aui-media-list-item-inner">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-text bottom">
                            <div class="aui-list-item-title">文档标题</div>
                        </div>
                        <div class="aui-info aui-margin-t-5 bottom" style="padding:0">
                            <div class="aui-info-item">
                                <img src="../image/liulangnan.png" style="width:1rem" class="aui-img-round" />
                                <span class="aui-margin-l-5">Admin</span>
                            </div>
                            <div class="aui-info-item">2015-07-14 10:31</div>
                        </div>
                        <div class="aui-list-item-text bottom">
                            文档内容文档内容文档内容文档内容文档内容文档内容文档内容文档内容文档内容文档内容文档内容文档内容文档内容文档内容
                        </div>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-media-list-item-inner">
                    <div class="aui-list-item-media">
                        <img src="../image/word.png">
                    </div>
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-text">
                            <div class="aui-list-item-title">附件</div>
                            <div class="aui-list-item-right">2015-07-14 10:31</div>
                        </div>
                        <div class="aui-list-item-text">
                            附件标题
                        </div>
                    </div>
                </div>
            </li> -->
        </ul>
    </div>

    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-media-list" id="commentList">
            <!-- <li class="aui-list-item">
                <div class="aui-info">
                    <div class="aui-info-item">
                        <img src="../image/liulangnan.png" style="width:1rem" class="aui-img-round" />
                        <span class="aui-margin-l-5">流浪男</span>
                        </div>
                    <div class="aui-info-item">2015-07-14 10:31</div>
                </div>
                <div class="aui-media-list-item-inner">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-text">
                            在下方我们加入了aui-info信息条
                        </div>
                    </div>
                </div>
            </li> -->
        </ul>
    </div>
    
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../css/font/iconfont.js" ></script>
<script type="text/javascript">
    apiready = function(){
        // 加载模块
        docReader = api.require('docReader');
        // 加载数据
        // $api.setStorage("daily_index", 0);
        load();
        //上拉翻页
        /*api.addEventListener({
            name : 'scrolltobottom'
        }, function(ret, err) {
            $api.setStorage("daily_index", $api.getStorage("daily_index") - 0 + 1);
            load();
        });*/
        
        function load () {
            // 加载内容
            api.ajax({
                url: ServeUrl + 'm=File&a=getFileDetails',
                method: 'post',
                data: {
                    values: {
                        id: api.pageParam.id,
                        // index: $api.getStorage("daily_index"),
                    },
                },
                dataType : 'json',
            }, function(ret, err) {
                if (ret) {
                    // 遍历文档内容
                    var str = '';
                    str += '<li class="aui-list-item">';
                    str += '<div class="aui-media-list-item-inner">';
                    str += '    <div class="aui-list-item-inner">';
                    str += '        <div class="aui-list-item-text bottom">';
                    str += '            <div class="aui-list-item-title">'+ret.file.title+'</div>';
                    str += '        </div>';
                    str += '        <div class="aui-info aui-margin-t-5 bottom" style="padding:0">';
                    str += '            <div class="aui-info-item">';
                    if (ret.file.user_img) {
                        str += '                <img src="'+ServeIp+'/include/data/headImg/'+ret.file.user_img+'" style="width:1rem"  class="aui-img-round" />';
                    } else {
                        str += '                <img src="../image/emptyHead.jpg" style="width:1rem" class="aui-img-round" />';
                    }
                    str += '                <span class="aui-margin-l-5">'+ret.file.create_user+'</span>';
                    str += '            </div>';
                    str += '            <div class="aui-info-item">'+ret.file.createtime+'</div>';
                    str += '        </div>';
                    str += '        <div class="bottom">'+ret.file.content+'</div>';
                    str += '    </div>';
                    str += '</div>';
                    str += '</li>';
                    if (ret.file.faq_file) {
                        var url = ServeIp+ret.file.file_path+ret.file.faq_file;
                        str += '<li class="aui-list-item">';
                        str += '<div class="aui-media-list-item-inner" onclick="download('+"'"+url+"','"+ret.file.faq_file+"'"+')">';
                        str += '    <div class="aui-list-item-media">'+ret.file.icon+'</div>';
                        str += '    <div class="aui-list-item-inner">';
                        str += '        <div class="aui-list-item-text aui-list-item-title">附件</div>';
                        str += '        <div class="aui-list-item-text">'+ret.file.faq_file+'</div>';
                        str += '    </div>';
                        str += '</div>';
                        str += '</li>';
                    }
                    $('#fileDetails').empty().html(str);

                    // 遍历评论
                    if (ret.comment) {
                        // alert(ret.comment)
                        var comment = '';
                        for (var i = 0; i < ret.comment.length; i++) {
                            comment += '<li class="aui-list-item" onclick="replyOpenWin(this)" data-name="reply-frm" data-id="'+ret.comment[i].id+'" data-user="'+ret.comment[i].create_user+'">';
                            comment += '    <div class="aui-info" style="padding-bottom:0">';
                            comment += '        <div class="aui-info-item">';
                            if (ret.comment[i].user_img) {
                                comment += '        <img src="'+ServeIp+'/include/data/headImg/'+ret.comment[i].user_img+'" style="width:1rem"  class="aui-img-round" />';
                            } else {
                                comment += '        <img src="../image/emptyHead.jpg" style="width:1rem" class="aui-img-round" />';
                            }
                            if (ret.comment[i].pid == 0) {
                                comment += '        <span class="aui-margin-l-5">'+ret.comment[i].create_user+'</span>';
                            } else {
                                comment += '        <span class="aui-margin-l-5 aui-margin-r-5">'+ret.comment[i].create_user+'</span>';
                                comment += '        <span class="aui-list-item-title">回复</span>';
                                comment += '        <span class="aui-margin-l-5">'+ret.comment[i].pcreate_user+'</span>';
                            }
                            comment += '        </div>';
                            comment += '    </div>';
                            comment += '    <div class="aui-media-list-item-inner" style="padding-top:0;padding-bottom:0">';
                            comment += '        <div class="aui-list-item-inner" style="padding-top:5px;padding-bottom:0">';
                            comment += '            <div class="aui-list-item-text">'+ret.comment[i].comment_content+'</div>';
                            comment += '        </div>';
                            comment += '    </div>';
                            comment += '</li>';
                        }
                        $('#commentList').empty().html(comment);

                        // alert(comment)
                    }
                    // api.alert({ msg: JSON.stringify(ret.comment) });
                } else {
                    api.toast({
                        msg:'评论加载失败!'
                    });
                }
            });
        }
    
        // download();
    };
    // 回复评论
    function replyOpenWin(tag) {
        var name = tag.getAttribute('data-name');
        var cid = tag.getAttribute('data-id');
        var user = tag.getAttribute('data-user');
        // alert(user);return false
        $api.setStorage( 'backFrame' , name );  //设置需要关闭的frame
        api.openFrame({
            name: name,
            url : 'openWin.html',
            rect: {
                x: 0,
                y: 0,
                w: api.winWidth,
                h: api.winHeight
            },
            pageParam:{
                id : api.pageParam.id, // 文章id
                user : user, // 文章id
                cid : cid, // 评论id
            }
        });
    }
    // 下载文件
    function download (url, name) {
        // alert(url)
        api.download({
            url: url,
            report: false,
            cache: true,
            savePath: 'fs://download/'+name,
            allowResume: true
        }, function(ret, err) {
            if (ret.state == 1) {
                //下载成功
                // alert(ret.savePath)；
                openFile(ret.savePath)
            } else if (ret.state == 2) {} {
                // alert('下载失败');

            }
        });
    }

    function openFile (path) {
        docReader.open({
            path: path
        }, function(ret, err) {
            if (ret.status) {
                api.toast({
                    msg:'预览成功!'
                });
            } else {
                api.toast({
                    msg:'预览失败!'
                });
            }
        });
    }


    // 打开窗口
    function openWin(name) {
        api.openWin({
            name: name,
            url: name+'_win.html',
        });
    }

    // 打开frame
    function openFrame (name) {
        api.openFrame({
            name: 'date_detail',
            url: 'date_detail_frm.html',
        });
    }

    
    
</script>
</html>